import axios from "axios";
import Vue from "vue"
import Vuex from "vuex"


//2. 使用vuex插件
Vue.use(Vuex);


//3.实例化一个vuex仓库,并暴露
//4. 给仓库传入配置(state mutations actions getters modules)
export default new Vuex.Store({
    state: {
      count: 0,
      movieList:[],
    },
    mutations:{
      increment(state,payload){
        state.count += payload.n
      },
      setMovieList(state,payload){
        state.movieList = payload.movieList;
      },
    },
    actions:{
      async getMovieList({commit}){
        const result = await axios.get("https://pcw-api.iqiyi.com/search/recommend/list?channel_id=1&data_type=1&mode=11&page_id=2&ret_num=48&session=b9fd987164f6aa47fad266f57dffaa6a");
        
        commit("setMovieList",{movieList: result.data.data.list})
      },
    },
    getters:{
      movieName3_6(state){
        return state.movieList.filter((item)=>{
          return item.name.length > 2 && item.name.length < 7;
        })
      }
    }
  });